﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AG.Editor.Core.Data;
using AG.Editor.Core.Metadata;

namespace AG.Editor.Windows
{
    public partial class AGSelectModelWindow : Form
    {
        public AGModelRef SelectedModel;

        private AGEProject _project;
        public AGSelectModelWindow(AGEProject project)
        {
            InitializeComponent();

            _project = project;

            //_ctlListCategory.DisplayMember = "Name";
            //_ctlListModel.DisplayMember = "Name";

            _ctlListCategory.SelectedIndexChanged += new EventHandler(_ctlListCategory_SelectedIndexChanged);
            _ctlListCategory.DataSource = project.TProject.ModelCategories;
        }

        void _ctlListCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            AGModelCategory selCategory = _ctlListCategory.SelectedItem as AGModelCategory;
            if (selCategory == null)
            {
                return;
            }

            List<AGModelRef> modelList = _project.GetModelRefList(selCategory);
            _ctlListModel.DataSource = modelList;
        }

        private void _ctlBtnOK_Click(object sender, EventArgs e)
        {
            if (_ctlListCategory.SelectedItem == null || _ctlListModel.SelectedItem == null)
            {
                return;
            }
            SelectedModel = _ctlListModel.SelectedItem as AGModelRef;

            DialogResult = System.Windows.Forms.DialogResult.OK;
        }
    }
}
